import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:zmcy_flutter/service/global_config_service.dart';

import 'common/routes.dart';
import 'common/sharedPreferences_helper.dart';
import 'service/auth_service.dart';

final RouteObserver<PageRoute> _routeObserver = RouteObserver<PageRoute>();

void main() async {
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  }
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
  /// 注册回调
  AssetPicker.registerObserve();
  // Enables logging with the photo_manager.
  PhotoManager.setLog(true);
  await SharedPreferencesHelper.init();
  await Get.putAsync(() => AuthService().init());
  Get.put(GlobalConfigService()).getEmojiConfig();
  runApp(const MyApp());

  Get.put(_routeObserver);
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'FlowGPT',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      navigatorObservers: [_routeObserver],
      unknownRoute: Routes.unknown_page,
      initialRoute: Routes.HOME,
      getPages: Routes.routes,
    );
  }
}
